package cn.kgc.mes.routeproduct.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;

import cn.kgc.mes.common.core.plus.response.Result;
import cn.kgc.mes.common.core.plus.response.ResultUtil;
import cn.kgc.mes.common.core.plus.dto.common.CommonDataPageResponse;
import cn.kgc.mes.common.core.plus.response.StatusResponse;

import cn.kgc.mes.routeproduct.domain.vo.RouteProductVo;
import cn.kgc.mes.routeproduct.business.RouteProductBusiness;

/**
 * 产品制程控制器
 * 
 * @author ruoyi
 * @date 2025-09-14
 */
@RestController
@RequestMapping("/routeproduct/routeproduct")
public class RouteProductController {

    @Resource
    RouteProductBusiness business;

    /**
     * 分页查询产品制程列表
     */
//    @PreAuthorize("@ss.hasPermi('routeproduct:routeproduct:list')")
    @PostMapping("/page")
    public Result page(@RequestBody RouteProductVo vo) {
        CommonDataPageResponse<RouteProductVo> response = business.page(vo);

        return ResultUtil.success(response);
    }

    /**
     * 获取产品制程详细信息
     */
//    @PreAuthorize("@ss.hasPermi('routeproduct:routeproduct:query')")
    @PostMapping("/info")
    public Result info(@RequestBody RouteProductVo vo) {

        RouteProductVo info = business.info(vo);

        return ResultUtil.success(info);
    }

    /**
     * 新增产品制程
     */
//    @PreAuthorize("@ss.hasPermi('routeproduct:routeproduct:add')")
    @PostMapping("/add")
    public Result add(@RequestBody RouteProductVo vo) {

        StatusResponse response = business.add(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 修改产品制程
     */
//    @PreAuthorize("@ss.hasPermi('routeproduct:routeproduct:edit')")
    @PostMapping("/update")
    public Result update(@RequestBody RouteProductVo vo) {

        StatusResponse response = business.update(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 删除产品制程
     */
//    @PreAuthorize("@ss.hasPermi('routeproduct:routeproduct:remove')")
    @PostMapping("/delete")
    public Result delete(@RequestBody RouteProductVo vo) {

        StatusResponse response = business.delete(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

}
